package com.zjj.spring.read.xml.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * <pre>
 * 名字	注入的依赖
 * ApplicationContextAware			声明的ApplicationContext
 * ApplicationEventPlulisherAware	ApplicationContext中的事件发布器
 * BeanClassLoaderAware				加载Bean使用的类加载器
 * BeanFactoryAware					声明的BeanFactory
 * BeanNameAware					Bean的名字
 * BootstrapContextAware			容器运行的资源适配器BootstrapContext，通常仅在JCA环境下有效
 * LoadTimeWeaverAware				加载期间处理类定义的weaver
 * MessageSourceAware				解析消息的配置策略
 * NotificationPublisherAware		Spring JMX通知发布器
 * PortletConfigAware				容器当前运行的PortletConfig，仅在web下的Spring ApplicationContext中可见
 * PortletContextAware				容器当前运行的PortletContext，仅在web下的Spring ApplicationContext中可见
 * ResourceLoaderAware				配置的资源加载器
 * ServletConfigAware				容器当前运行的ServletConfig，仅在web下的Spring ApplicationContext中可见
 * ServletContextAware				容器当前运行的ServletContext，仅在web下的Spring ApplicationContext中可见
 * 声明，上面这些接口的使用是违反IoC原则的，除非必要，最好不要使用
</pre>
 * @author zhuangjiajie778
 */
public class AwareBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware {
    
	private String beanName;
	private ApplicationContext applicationContext;
	private BeanFactory beanFactory;

	/**BeanNameAware*/
	public void setBeanName(String beanName) {
		System.out.println("【1】---------------Enter AwareBean.setBeanName() from BeanNameAware---------------");
		System.out.println("【1】Original beanName = " + beanName + " - 可自定义AwareBean的beanName");
		this.beanName = "com.zjj.CustemBeanName";
		System.out.println("【1】custom   beanName = " + this.beanName );
		System.out.println("【1】---------------Exit  AwareBean.setBeanName() from BeanNameAware---------------");
		System.out.println();
	}
	/**BeanFactoryAware*/
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("【2】---------------Enter AwareBean.setBeanFactory() from BeanFactoryAware---------------");
		System.out.println("【2】beanfactory = " + beanFactory);
		System.out.println("【2】---------------Enter AwareBean.setBeanFactory() from BeanFactoryAware---------------");
		this.beanFactory = beanFactory;
		System.out.println();
	}
	/**ApplicationContextAware*/
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		System.out.println("【3】----------------Enter AwareBean.setApplicationContext() from ApplicationContextAware---------------");
		System.out.println("【3】applicationContext = " + applicationContext);
		System.out.println("【3】----------------Exit  AwareBean.setApplicationContext() from ApplicationContextAware---------------");
		this.applicationContext = applicationContext;
		System.out.println();
	}
	
	public ApplicationContext getApplicationContext(){
		return this.applicationContext;
	}

}